<%@ Page Language="c#" Inherits="PHSRAG.Insight21.Purchasing.UserOrderDetails" CodeFile="UserOrderDetails.aspx.cs" %>

<%@ Register TagPrefix="cc1" Namespace="PHSRAG.Insight21.InsightWebControls" Assembly="PHSRAG.Insight21.InsightWebControls" %>
<%@ Register TagPrefix="cc2" Namespace="PHSRAG.WebControls" Assembly="PHSRAG.WebControls" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>UserOrderDetails</title>
    <link href="../Insight21.css" type="text/css" rel="stylesheet" />

    <script language="javascript" type="text/javascript">			
			var isLineDirty = false;var isHeaderDirty = true;			
			var headerIDs = new Array('orderTypeList', 'orderNumber', 'vendorName', 'invoiceNumber',
				'transactionDate', 'requistionNumber', 'vendorNumber', 'invoiceDate', 'headerComment');			
			var headerValues = new Array('', '', '', '', '', '','', '', '');			
			var looseChangesMsg = 'You have made changes that you have not saved.  Do you wish to continue?';
				
			function SetHeaderDirty(){
				isHeaderDirty = true;				
			}
			
			function SetLineDirty(){
				isLineDirty = true;				
			}			
			
			// Checks if the intial values saved in headerValues array have changed,
			// if yes it prompts the user that he will loose the changes he has done.
			function ConfirmLooseChanges(){
				if (isHeaderDirty)
				{
					// check to see if any changes to the data entry fields have been made
					for (var index = 0; index < headerValues.length; index++)
					{						
						var element = window.document.getElementById(headerIDs[index]);						
						if (element)
						{
							if ((element.type == 'select-one') && (headerValues[index] != element.value))
							{
								return confirm(looseChangesMsg);
								break;
							}
							else if ((element.type == 'text') && (element.value != headerValues[index]))
							{
								return confirm(looseChangesMsg);
								break;						
							}
							else if(((element.type != 'text') && (element.type != 'select-one')) && 
							(element.innerText != headerValues[index]))
							{							
								return confirm(looseChangesMsg);
								break;
							}							
						}						
					}					
				}
				if(isLineDirty)
				{
					return confirm(looseChangesMsg);
				}		
			}		
			
			//Shows a message box before deleting user order
			function ConfirmDeleteUserOrder()
			{
				return confirm("Are you sure you want to delete this order?");
			}
			
			//Shows a message box before deleting line item
			function ConfirmDeleteLineItem()
			{
				return confirm("Are you sure you want to delete this line item?");
			}		
			
    </script>

</head>
<body>
    <form method="post" id="UserOrderDetailsForm" runat="server">
        <table class="Container" width="100%">
            <tr>
                <td>
                    <table class="Header" width="100%">
                        <tr>
                            <td>
                                <cc1:Header ID="header" runat="server"></cc1:Header>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <cc1:PurchasingSubNavigation ID="purchasingSubModuleNavigation" runat="server"></cc1:PurchasingSubNavigation>
                            </td>
                        </tr>
                        <tr>
                            <td class="Pending">
                                <cc2:BreadCrumb ID="breadCrumb" runat="server"></cc2:BreadCrumb>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                &nbsp;</td>
                        </tr>
                    </table>
                    <table id="dynamicTable" class="Invisible" cellspacing="10">
                        <tr>
                            <td>
                                <cc2:ActivityIndicator ID="activityIndicator" runat="server" ContainerID="dynamicTable">
                                </cc2:ActivityIndicator>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <cc2:Annunciator ID="annunciator" runat="server" ContainerID="dynamicTable"></cc2:Annunciator>
                            </td>
                        </tr>
                    </table>
                    <table class="Annunciator">
                        <tr>
                            <td style="width: 100%" colspan="2">
                                <asp:ValidationSummary ID="validationSummary" runat="server" EnableClientScript="True"
                                    BorderStyle="None" DisplayMode="List" ForeColor="Blue" HeaderText="Please correct the errors highlighted below">
                                </asp:ValidationSummary>
                            </td>
                        </tr>
                    </table>
                    <table class="DataTitle" width="100%" cellspacing="0">
                        <tr>
                            <td>
                                &nbsp;Header</td>
                        </tr>
                    </table>
                    <table class="LikeDataGrid" cellspacing="0" cellpadding="0" width="100%" border="1">
                        <tr class="DataGridHeader">
                            <td>
                                <span style="white-space: nowrap">Order Type</span>
                            </td>
                            <td>
                                <span style="white-space: nowrap">ID #</span>
                            </td>
                            <td id="vendorNameLabel" style="width: 90px">
                                <span style="white-space: nowrap">Vendor Name</span>
                            </td>
                            <td id="invoiceNumberLabel" style="width: 70px">
                                <span style="white-space: nowrap">Invoice #</span>
                            </td>
                            <td id="transDateLabel" style="width: 100px">
                                <span style="white-space: nowrap">Transaction Date</span>
                            </td>
                            <td id="reqNumLabel" style="width: 70px">
                                <span style="white-space: nowrap">Requisition #</span>
                            </td>
                            <td id="vendorIDLabel" style="width: 85px">
                                <span style="white-space: nowrap">Vendor ID</span>
                            </td>
                            <td id="invoiceDateLabel" style="width: 100px">
                                <span style="white-space: nowrap">Invoice Date</span>
                            </td>
                            <td style="width: 100px">
                                <span style="white-space: nowrap">Comment</span>
                            </td>
                        </tr>
                        <tr>
                            <td style="width:50px">
                                <asp:DropDownList ID="orderTypeList" runat="server" Enabled="True" CssClass="FlatDropDown">
                                </asp:DropDownList></td>
                            <td style="width:95px">
                                <asp:TextBox ID="orderNumber" runat="server" CssClass="FlatText" MaxLength="10" Width="87%"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="orderNumberValidator" runat="server" EnableClientScript="False"
                                    Display="Static" ControlToValidate="orderNumber"></asp:RequiredFieldValidator></td>
                            <td id="vendorNameCell" style="width:100px">
                                <asp:TextBox ID="vendorName" runat="server" CssClass="FlatText" Width="100%"></asp:TextBox></td>
                            <td id="invoiceNumberCell">
                                <asp:TextBox ID="invoiceNumber" runat="server" CssClass="FlatText" Width="100%"></asp:TextBox></td>
                            <td id="transDateCell" align="right" style="width:100px">
                                <cc2:Calendar ID="transactionDate" runat="server" CssClass="FlatText" Width="100%"
                                    ToolTip="Select transaction date" BeginYear="1990" DropDownListNavigation="true"
                                    EndYear="2050" Height="10" Prompt="-- Select --"></cc2:Calendar>
                            </td>
                            <td id="reqNumCell" style="width:70px">
                                <asp:TextBox ID="requistionNumber" runat="server" CssClass="FlatText" Width="100%"></asp:TextBox></td>
                            <td id="vendorNumCell" style="width:85px">
                                <asp:TextBox ID="vendorNumber" runat="server" CssClass="FlatText" Width="100%"></asp:TextBox></td>
                            <td id="invoiceDateCell" align="right" style="width:100px">
                                <cc2:Calendar ID="invoiceDate" runat="server" CssClass="FlatText" Width="100%" ToolTip="Select invoice date"
                                    BeginYear="1990" DropDownListNavigation="true" EndYear="2050" Height="10" Prompt="-- Select --">
                                </cc2:Calendar>
                            </td>
                            <td style="width:300px">
                                <asp:TextBox ID="headerComment" runat="server" CssClass="FlatText" Height="50px"
                                    Width="100%" Wrap="True" TextMode="MultiLine"></asp:TextBox></td>
                        </tr>
                    </table>
                    <br />
                    <table class="DataTitle" width="100%" cellspacing="0">
                        <tr>
                            <td>
                                &nbsp;Line</td>
                        </tr>
                    </table>
                    <table width="100%" cellspacing="0">
                        <tr>
                            <td>
                                <asp:DataGrid ID="lineItemsDataGrid" runat="server" CssClass="DataGrid" Width="100%"
                                    ShowFooter="True" AutoGenerateColumns="False" AllowSorting="False">
                                    <FooterStyle CssClass="DataGridFooter"></FooterStyle>
                                    <EditItemStyle CssClass="DataGridEditRow"></EditItemStyle>
                                    <AlternatingItemStyle CssClass="DataGridAlternatingItem"></AlternatingItemStyle>
                                    <ItemStyle CssClass="DataGridItem"></ItemStyle>
                                    <HeaderStyle CssClass="DataGridHeader"></HeaderStyle>
                                    <Columns>
                                        <asp:TemplateColumn HeaderText="Account #" HeaderStyle-Width="100" SortExpression="AccountNumber">
                                            <ItemTemplate>
                                                <asp:TextBox ID="accountNumber" runat="server" Width="87%" CssClass="flattext" />
                                                <asp:RequiredFieldValidator ID="accountNumberValidator" runat="server" ControlToValidate="accountNumber"
                                                    Display="Static" Width="0" EnableClientScript="False"></asp:RequiredFieldValidator>
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                Total:
                                            </FooterTemplate>
                                        </asp:TemplateColumn>
                                        <asp:TemplateColumn HeaderText="Fund #" HeaderStyle-Width="100" SortExpression="FundNumber">
                                            <ItemTemplate>
                                                <asp:TextBox ID="fundNumber" runat="server" Width="87%" CssClass="flattext" />
                                                <asp:RequiredFieldValidator ID="fundNumberValidator" runat="server" ControlToValidate="fundNumber"
                                                    Display="Static" Width="0" EnableClientScript="False" CssClass="Warnings"></asp:RequiredFieldValidator>
                                            </ItemTemplate>
                                        </asp:TemplateColumn>
                                        <asp:TemplateColumn HeaderText="Amount" FooterStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right"
                                            HeaderStyle-Width="95" SortExpression="Amount">
                                            <ItemTemplate>
                                                <asp:TextBox ID="amount" runat="server" Width="80" CssClass="FlatTextCurrency" />
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                <asp:Label ID="total" runat="server" CssClass="expandingGridCurrency" />
                                            </FooterTemplate>
                                        </asp:TemplateColumn>
                                        <asp:TemplateColumn HeaderText="Requestor" HeaderStyle-Width="150" ItemStyle-HorizontalAlign="Center"
                                            SortExpression="RequestorName">
                                            <ItemTemplate>
                                                <asp:TextBox ID="requestor" runat="server" Width="140" CssClass="flattext" />
                                            </ItemTemplate>
                                        </asp:TemplateColumn>
                                        <asp:TemplateColumn HeaderText="Comment" HeaderStyle-Width="200" ItemStyle-HorizontalAlign="Center"
                                            SortExpression="Comment">
                                            <ItemTemplate>
                                                <asp:TextBox ID="distributionComment" runat="server" CssClass="FlatText" Height="50px"
                                                    Width="100%" Wrap="True" TextMode="MultiLine" />
                                            </ItemTemplate>
                                        </asp:TemplateColumn>
                                        <asp:TemplateColumn HeaderText="Actions" ItemStyle-Wrap="False" HeaderStyle-Width="100"
                                            ItemStyle-HorizontalAlign="Center">
                                            <ItemTemplate>
                                                <asp:ImageButton ID="deleteDistribution" ImageUrl="../Images/b_delete.gif" runat="server"
                                                    Visible="False" CommandName="delete"></asp:ImageButton>
                                            </ItemTemplate>
                                        </asp:TemplateColumn>
                                    </Columns>
                                </asp:DataGrid></td>
                        </tr>
                    </table>
                    <br />
                    <table width="100%">
                        <tr>
                            <td style="width:50%">
                                &nbsp;</td>
                            <td align="right" style="width:50%">
                                <asp:ImageButton ID="addDistribution" ImageUrl="../Images/b_adddist.gif" runat="server">
                                </asp:ImageButton>
                                <asp:ImageButton ID="deleteUserOrder" ImageUrl="../Images/b_delete.gif" runat="server"
                                    Visible="True"></asp:ImageButton>
                                &nbsp;<asp:ImageButton ImageUrl="../Images/b_cancel.gif" ID="cancel" runat="server">
                                </asp:ImageButton>
                                &nbsp;<asp:ImageButton ImageUrl="../Images/b_save.gif" ID="save" runat="server" Visible="True">
                                </asp:ImageButton>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </form>

    <script type="text/javascript">
			// adds the given function to window.onload and enures that 
			// the specfied javascript function is executed on page load
			function AddLoadEvent(func) 
			{
				var oldonload = window.onload;
				if (typeof window.onload != 'function') 
				{
					window.onload = func;
				} 
				else 
				{
					window.onload = function() 
					{
						if (oldonload) 
						{
							oldonload();
						}
						func();
					}
				}
			}				
			
			//function to manage display of order header columns based on order type
			AddLoadEvent(function DisplayHeaderColumns()
			{		
				SetHeaderDirty();
				//04/04/2008 - TrackIt 8185 jml29 - fix for an error "window.document.UserOrderDetails.orderTypeList"			
				//var orderType = window.document.UserOrderDetails.orderTypeList.value;	
				var orderType = window.document.getElementById(headerIDs[0]).value;
				switch(orderType)
				{
					//when selected value is purchase order
					case '1':					
						window.document.getElementById('vendorNameLabel').style.display = 'inline';
						window.document.getElementById('invoiceNumberLabel').style.display = 'inline';
						window.document.getElementById('reqNumLabel').style.display = 'inline';
						window.document.getElementById('vendorIDLabel').style.display = 'inline';
						window.document.getElementById('invoiceDateLabel').style.display = 'inline';
						
						window.document.getElementById('vendorNameCell').style.display = 'inline';
						window.document.getElementById('invoiceNumberCell').style.display = 'inline';	
						window.document.getElementById('reqNumCell').style.display = 'inline';
						window.document.getElementById('vendorNumCell').style.display = 'inline';
						window.document.getElementById('invoiceDateCell').style.display = 'inline';
						break;
					//when selected value is travel voucher or cheque request
					case '2':
					case '3':
						window.document.getElementById('vendorNameLabel').style.display = 'inline';
						window.document.getElementById('invoiceNumberLabel').style.display = 'inline';
						window.document.getElementById('reqNumLabel').style.display = 'none';
						window.document.getElementById('vendorIDLabel').style.display = 'inline';
						window.document.getElementById('invoiceDateLabel').style.display = 'inline';
						
						window.document.getElementById('vendorNameCell').style.display = 'inline';
						window.document.getElementById('invoiceNumberCell').style.display = 'inline';
						window.document.getElementById('reqNumCell').style.display = 'none';
						window.document.getElementById('vendorNumCell').style.display = 'inline';
						window.document.getElementById('invoiceDateCell').style.display = 'inline';
						break;
					//when selected value is journal entry or petty cash
					case '4':
					case '5':
						window.document.getElementById('vendorNameLabel').style.display = 'none';
						window.document.getElementById('invoiceNumberLabel').style.display = 'inline';
						window.document.getElementById('reqNumLabel').style.display = 'none';
						window.document.getElementById('vendorIDLabel').style.display = 'none';
						window.document.getElementById('invoiceDateLabel').style.display = 'inline';
						
						window.document.getElementById('vendorNameCell').style.display = 'none';
						window.document.getElementById('invoiceNumberCell').style.display = 'inline';
						window.document.getElementById('reqNumCell').style.display = 'none';
						window.document.getElementById('vendorNumCell').style.display = 'none';
						window.document.getElementById('invoiceDateCell').style.display = 'inline';
						break;				
				}														
			})
			
			
			AddLoadEvent(function PopulateHeaderValueArray()
			{
				// assign the loaded values to the items in the headerValues array
				for (var index = 0; index < headerIDs.length; index++)
				{
					var element = window.document.getElementById(headerIDs[index]);
					if (element)
					{
						if (element.type == 'select-one')
							headerValues[index] = element.value;
						else if(element.type == 'text')
							headerValues[index] = element.value;
						else
							headerValues[index] = element.innerText;						
					}					
				}      
			})			
    </script>

</body>
</html>
